﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using MockPrjTeam2.Biz;
using MockPrjTeam2.Common;
using MockPrjTeam2.Entity;

namespace MockPrjTeam2.Common
{
    public class Utilities
    {


        public static int ToInt(DataRow dataRow, string columnName)
        {
            var result = 0;
            if (dataRow[columnName] != DBNull.Value)
            {
                result = Convert.ToInt32(dataRow[columnName]);
            }

            return result;
        }

        public static string ToString(DataRow dataRow, string columnName)
        {
            string result = string.Empty;
            if (dataRow[columnName] != DBNull.Value)
            {
                result = dataRow[columnName].ToString().Trim();
            }

            return result;
        }

        public static DateTime ToDateTime(DataRow dataRow, string columnName)
        {
            DateTime result = DateTime.MinValue;
            if (dataRow[columnName] != DBNull.Value)
            {
                result = Convert.ToDateTime(dataRow[columnName].ToString(), CultureInfo.CurrentCulture);
            }

            return result;
        }

        public static bool ToNullableBoolean(DataRow dataRow, string columnName)
        {
            bool result = false;

            if (dataRow[columnName] != DBNull.Value)
            {
                result = Convert.ToBoolean(dataRow[columnName], CultureInfo.CurrentCulture);
            }

            return result;
        }
    }
}